var _COMBOBOX = {
	

	TowerFloorUnitAddrCombo : function(towerId, floorId , unitId, address , roomId , towerObj) {
	    if(towerObj != null){
        	    var v1= towerObj['tower'];
                    var v2= towerObj['floor'];
                    var v3= towerObj['unitNo'];
                    var v4= towerObj['address'];
                    $('#' + towerId).append($('<option></option>').val(v1).html(v1));
                    $('#' + floorId).append($('<option></option>').val(v2).html(v2));
                    $('#' + unitId).append($('<option></option>').val(v3).html(v3));
        	    $('#' + address).append($('<option></option>').val(v4).html(v4));
	    }else{

		$.post('../combo/getTower', {
        	}, function (result) {
        	    var obj = result['items'];
        	    var v1 = '';
//        	    var v2 = '';
//        	    var v3= '';
        	    var v4= '';
        	    
        	    _COMBOBOX.ResetAllTowerCriteria(towerId, floorId , unitId, address , roomId);
        	    $("#"+towerId+" option").remove();
        	    $("#"+address+ " option").remove();
        	    $("#"+towerId).append($('<option>---- All ----</option>').val(''));
        	    $("#"+address).append($('<option>---- All ----</option>').val(''));
        	    $.each(obj, function(val, text) {
        		
        		// ---- Tower----
        		if(text['tower'] != v1){
        		    v1 = text['tower'] ;
//        		    var sel = (selected == v1)?  'selected' :'';
//        		    $('#' + towerId).append($('<option '+sel+'></option>').val(v1).html(v1));
        		    $('#' + towerId).append($('<option ></option>').val(v1).html(v1));
        		}
        		
        		//---- Address ----
        		if(text['address'] != v4){
        		    v4 = text['address'] ;
        		    $('#' + address).append($('<option></option>').val(v4).html(v4));
        		}	
        	    });
        	    
    		    
        	});
        	
        	$('#' + towerId).change(function() {
        	    _COMBOBOX.FloorCombo(towerId, floorId , unitId, address, null, roomId);
        	});
        	
        	$('#' + floorId).change(function() {
        	    _COMBOBOX.UnitCombo(towerId, floorId , unitId, address, null,  roomId);
        	});
        	
        	$('#' + unitId).change(function() {
        	    _COMBOBOX.AddressCombo(towerId, floorId , unitId, address, roomId);
        	});
        	
        	$('#' + address).change(function() {
        	    _COMBOBOX.AddressSearch(towerId, floorId , unitId, address, roomId);
        	});
	    }
        }
//        TowerFloorUnitAddrComboEdit : function(towerId, floorId , unitId, address , roomId) {
//            var v1= 'A';
//            var v2= '8';
//            var v3= '801';
//            var v4= '110/1';
//            $('#' + towerId).append($('<option></option>').val(v1).html(v1));
//            $('#' + floorId).append($('<option></option>').val(v2).html(v2));
//            $('#' + unitId).append($('<option></option>').val(v3).html(v3));
//	    $('#' + address).append($('<option></option>').val(v4).html(v4));
//    		    
//        }
        ,FloorCombo : function(towerId, floorId , unitId, address , selected, roomId) {
            _COMBOBOX.ResetAllTowerCriteria(null, floorId , unitId, address, roomId);
            if( $('#' + towerId).val() != ''){
        	$.post('../combo/getTower', {
        	    	'tower.tower':  $('#' + towerId).val()
            		}, function (result) {
            		    var obj = result['items'];
            		    var v = '';
            		    $.each(obj, function(val, text) {
                		if(text['floor'] != v){
                		    v = text['floor'] ;
                		    var sel = (selected == v)?  'selected' :'';
                		    $('#' + floorId).append($('<option '+sel+'></option>').val(v).html(v));
                		}	
                	    });
            	});
        	
            }
        },
        UnitCombo : function(towerId, floorId , unitId, address , selected, roomId) {
            _COMBOBOX.ResetAllTowerCriteria(null, null , unitId, address, roomId);
            if( $('#' + towerId).val() != '' && $('#' + floorId).val() != '') {
        	$.post('../combo/getTower', {
        	    	'tower.tower':  $('#' + towerId).val() ,
        	    	'tower.floor':  $('#' + floorId).val()
            		}, function (result) {
            		    var obj = result['items'];
            		    var v = '';
            		    $.each(obj, function(val, text) {
                		if(text['unitNo'] != v){
                		    v = text['unitNo'] ;
                		    var sel = (selected == v)?  'selected' :'';
                		    $('#' + unitId).append($('<option '+sel+'></option>').val(v).html(v));
                		}	
                	    });
            	});
        	
            }
        },
        AddressCombo : function(towerId, floorId , unitId, address, roomId) {
            if($('#' + unitId).val() != ''){
        	$.post('../combo/getTower', {
        	    	'tower.tower' :  $('#' + towerId).val() ,
        	    	'tower.floor' :  $('#' + floorId).val(),
        	    	'tower.unitNo':  $('#' + unitId).val()
            		}, function (result) {
            		    if(result['items']){
            			var obj =  result['items'][0];
            			_log(obj);
            			 $('#' + address).val(obj['address']);
            			 if(roomId){
            			     $('#' + roomId).val(obj['roomId']);
            			 }
            		    }
            	});
        	
            }else{
        	$('#' + address).val('');
        	$('#' + roomId).val('');
            }
        },
        AddressSearch : function(towerId, floorId , unitId, address, roomId) {
            _COMBOBOX.ResetAllTowerCriteria(towerId,  floorId , unitId, null, roomId);
            if($('#' + address).val() != ''){
        	$.post('../combo/getTower', {
        	    'tower.address':  $('#' + address).val()
        	}, function (result) {
        		var obj = result['items'];
        		_log(roomId);
        		_log(obj[0]['roomId']);
        		
        		$("#"+towerId).val( obj[0]['tower']);
        		    _COMBOBOX.FloorCombo(towerId, floorId , unitId, null, obj[0]['floor']);
        		    setTimeout(function() {
        			_COMBOBOX.UnitCombo(towerId, floorId , unitId, null, obj[0]['unitNo']);
        		    }, 200);
        		
        		 if(roomId){
//       			     $('#' + roomId).val(obj[0]['roomId']);
       			     $('#' + roomId).val(obj[0]['roomId']);
   			 }

        		
        	});
        	
            }
        },
        ResetAllTowerCriteria :function(towerId, floorId , unitId, address, roomId){
            _log('------ Reset ------');
            $("#"+floorId+" option").remove();
	    $("#"+unitId+ " option").remove();
	    $("#"+floorId).append($('<option>---- All ----</option>').val(''));
	    $("#"+unitId ).append($('<option>---- All ----</option>').val(''));
	    $("#"+address).val('');
	    $("#"+towerId).val('');
	    $("#"+roomId).val('');
        }
	,StatusCombo:function(id){
	    $("#"+id).append($('<option>---- All ----</option>').val(''));
	    $("#"+id).append($('<option>Active</option>').val('Y'));
	    $("#"+id).append($('<option>Inactive</option>').val('N'));
	}
	,OwnerTenantCombo:function(id){
	    $("#"+id).append($('<option>---- All ----</option>').val(''));
	    $("#"+id).append($('<option>Co-Owner</option>').val('C'));
	    $("#"+id).append($('<option>Tenant</option>').val('T'));
	}
	,RequireToCombo:function(id){
	    $("#"+id).append($('<option>---- All ----</option>').val(''));
	    $("#"+id).append($('<option>Concierge</option>').val('C'));
	    $("#"+id).append($('<option>Deposit</option>').val('D'));
	}
	,RoomStatusCombo:function(id){
	    $("#"+id).append($('<option>---- All ----</option>').val(''));
	    $("#"+id).append($('<option>Valiable</option>').val('Y'));
	    $("#"+id).append($('<option>Unvaliable</option>').val('N'));
	}
	,PaymentStatusCombo:function(id){
	    $("#"+id).append($('<option>---- All ----</option>').val(''));
	    $("#"+id).append($('<option>Paid</option>').val('Y'));
	    $("#"+id).append($('<option>Not Paid</option>').val('N'));
	}
	,PriorityCombo:function(id){
	    $("#"+id).append($('<option>---- All ----</option>').val(''));
	    $("#"+id).append($('<option>Urgent</option>').val('U'));
	    $("#"+id).append($('<option>Standard</option>').val('S'));
	}
	,FnRoomCombo:function(id){
	    $("#"+id).append($('<option>---- All ----</option>').val(''));
	    $("#"+id).append($('<option>Party Room</option>').val('1'));
	    $("#"+id).append($('<option>Multi Pupose Room</option>').val('2'));
	    $("#"+id).append($('<option>Meeting Room</option>').val('3'));
	}
	
	
};


